﻿using System;
using SpLocalizer.Common.Extensions;

namespace Core.Threading.ThreadPools.TaskItems
{
    public sealed class ActionTaskItem : ITaskItem
    {
        public ActionTaskItem(Action action, TaskItemPriority priority)
        {
            if (action.IsNull())
                throw new ArgumentNullException("action", "action is null");
            if (!(Enum.IsDefined(typeof (TaskItemPriority), priority)))
                throw new ArgumentException("priority");
            Action = action;
            Priority = priority;
        }

        public ActionTaskItem(Action action)
        {
            if (action.IsNull())
                throw new ArgumentNullException("action", "action is null");
            Action = action;
            Priority = TaskItemPriority.Normal;
        }

        public Action Action { get; private set; }

        public TaskItemPriority Priority { get; private set; }

        #region ITaskItem Members

        public void DoWork()
        {
            Action();
        }

        #endregion
    }
}